import UserLogic from "../logic/UserLogic";
import HeroLogic from "../logic/HeroLogic";
import UserData from "../data/UserData";

export default class LoginModel {
    constructor()
    {

    }
    private static _instance:LoginModel;
    
    public static get instance() : LoginModel {
        if (!this._instance)
        {
            this._instance = new LoginModel();
        }
        return this._instance
    }
    /**
     * actionRandomHero
     */
    public actionRandomHero(callFunc:Function) {
        let heroObj:object = HeroLogic.instance.onRandomeHero()
        callFunc(heroObj)
    }
    /**
     * 创建用户
     */
    public actionCreateUser(name:string,sex:number,callFunc:Function) {
        UserLogic.instance.initUserData(name,sex)
        HeroLogic.instance.createInitHero()
        this.updateUserData()
        callFunc()
    }
    private _userData:UserData
    private updateUserData()
    {
        let userObj:object = UserLogic.instance.userObj
        if (!userObj)
        {
            return
        }
        if(!this._userData)
        {
            this._userData = new UserData()
        }
        this._userData.name = userObj["name"]
        this._userData.sex = userObj["sex"]
        this._userData.headId = userObj["headId"]
        this._userData.money = userObj["money"]
        this._userData.gold = userObj["gold"]
    }
    
    public get userData() : UserData {
        return  this._userData
    }
    
    /**
     * init
     */
    public init() {
        this.updateUserData()
    }
    //设置用户物品数据
    
}
